<template>
<div id="detail">
  <detail-nav-bar class="detail-nav"></detail-nav-bar>
  <scroll class="content" ref="scroll">
    <detail-swiper :topImages="topImages"></detail-swiper>
    <detail-base-info :goods="goods"></detail-base-info>
    <detail-shop-info :shop="shop"></detail-shop-info>
    <detail-goods-info :detailInfo="detailInfo" @imageLoad="imageLoad"></detail-goods-info>
    <detail-param-info :paramInfo="paramInfo"></detail-param-info>
    <detail-comment-info :commentInfo="commentInfo"></detail-comment-info>
  </scroll>
</div>
</template>

<script>
//1.引入内容组件
import DetailNavBar from './childComps/DetailNavBar'
import DetailSwiper from './childComps/DetailSwiper'
import DetailBaseInfo from './childComps/DetailBaseInfo'
import DetailShopInfo from './childComps/DetailShopInfo'
import Scroll from 'components/common/scroll/Scroll'
import DetailGoodsInfo from './childComps/DetailGoodsInfo'
import DetailParamInfo from './childComps/DetailParamInfo'
import DetailCommentInfo from './childComps/DetailCommentInfo'

//2.引入网络请求数据
import {
  getDetail,
  Goods,
  Shop,
  GoodsParam
} from 'network/detail'

export default {
  name: 'Detail',
  data() {
    return {
      iid: null,
      topImages: [],
      goods: {},
      shop: {},
      detailInfo: {},
      paramInfo: {},
      commentInfo: {},
      commentInfo: {
        text: '哈哈哈哈真好',
        user: '权7438'
      },
    }
  },
  created() {
    //1.获取iid，保存iid
    this.iid = this.$route.params.iid
    //console.log(this.$route)
    //2.根据iid请求数据
    getDetail(this.iid).then((res) => {
      //console.log(res)
      const data = res.result
      //1.获取顶部的轮播数据
      this.topImages = data.itemInfo.topImages
      //console.log(this.topImages)
      //3.获取轮播图下面的详情数据
      this.goods = new Goods(data.itemInfo, data.columns, data.shopInfo.services)
      //console.log(this.goods)
      //4.获取店铺信息，评分之类的
      this.shop = new Shop(data.shopInfo)
      //console.log(this.shop)
      //5.获取商品的详情数据
      this.detailInfo = data.detailInfo
      //console.log(this.detailInfo)
      //6.获取参数的信息
      this.paramInfo = new GoodsParam(data.itemParams.info, data.itemParams.rule)
      //console.log(this.paramInfo)
      //7.获取评论信息数据
      if (data.rate.cRate != 0) {
        //this.commentInfo = data.rate.list[0]
        console.log(this.commentInfo)
      }
    })
  },
  components: {
    DetailNavBar,
    DetailSwiper,
    DetailBaseInfo,
    DetailShopInfo,
    Scroll,
    DetailGoodsInfo,
    DetailParamInfo,
    DetailCommentInfo,
  },
  methods: {
    imageLoad() {
      this.$refs.scroll.refresh()
      //console.log('刷新了高度')
      //console.log(this.$refs.scroll)
    },
  },
}
</script>

<style scoped>
/* #detail {
  position: relative;
  z-index: 9;
  background-color: #fff;
  height: 100vh;
}

.detail-nav {
  position: relative;
  z-index: 9;
  background-color: #fff;
}

.content {
  height: calc(100% - 44px);
}
 */
#detail {
  position: relative;
  z-index: 9;
  background-color: #fff;
  height: 100vh;
}

.detail-nav {
  position: relative;
  z-index: 9;
  background-color: #fff;
}

.content {
  height: calc(100% - 44px);
}
</style>
